#include "constants.h"

#include "debug.h"
#include "objectlayout.h"
#include "objectmemory.h" 
#include "context.h"
#include "snapshot.h"
#include "primitives.h"
#include "arithmeticPrimitives.h"
#include "controlPrimitives.h"
#include "devicePrimitives.h"
#include "floatPrimitives.h"
#include "gcAndBecome.h"
#include "processAndSemaphore.h"
#include "storagePrimitives.h"
#include "subscriptPrimitives.h"
#include "systemPrimitives.h"
#include "interpretermain.h"

#ifdef PROGRAM
	#include <stdlib.h>
	#include <stdio.h>
	#include <string.h>
	#include <time.h>
	#include <pthread.h>
	#include <unistd.h>
	#define heapSize 0x0FFFFFFF //256 megabytes
	int heapSpace[heapSize/4]; 
	pthread_t thread;
	int millisecond_clock=0;
	void* timerLoop(void* ignore)
	{
		int MillisecondClockMask = 0x1FFFFFFF;
		for(;;)
		{
			usleep(1000);
			millisecond_clock += 1;
			millisecond_clock &= MillisecondClockMask;
		}
		return 0;
	}
	
	int main() {
		int* ptr = &heapSpace[0];
		FILE *f = fopen("oceania.image", "rb");
		if(f==0) PANIC("Can't open oceania.image");
		int read;
		while( (read=fread((void*)ptr,4,1024,f)) > 0 ) ptr += read;
		
		int x = pthread_create(&thread, NULL, timerLoop, NULL);
		
		interpreterMain( &heapSpace[0], heapSize );
	}
	
	
#endif
#ifdef KERNEL
	#include "../primordialsoup/constants.h"
	#include "../primordialsoup/typedefs.h"
	#include "../primordialsoup/common.h"
	#include "../primordialsoup/terminal.h"
	#include "../primordialsoup/interrupt.h"
	extern int millisecond_clock;
	extern video_descriptor video_info;
#endif

#include "debug.c"
#include "objectlayout.c"
#include "objectmemory.c" 
#include "context.c"
#include "snapshot.c"
#include "primitives.c"
#include "arithmeticPrimitives.c"
#include "controlPrimitives.c"
#include "devicePrimitives.c"
#include "floatPrimitives.c"
#include "gcAndBecome.c"
#include "processAndSemaphore.c"
#include "storagePrimitives.c"
#include "subscriptPrimitives.c"
#include "systemPrimitives.c"
#include "interpretermain.c"
